package czk.concrent.threadpool.dymicthreadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 修改素色队列容量
 *
 * @Author:ChenZhangKun
 * @Date: 2022/9/5 22:02
 */
public class BlockQueueDemo {
    public static void main(String[] args) {
        MyLinkedBlockingQueue blockingQueue = new MyLinkedBlockingQueue(5);
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + "开始执行put(" + i + ")");
                try {
                    blockingQueue.put(i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "put(" + i + ")成功，剩余" + blockingQueue.remainingCapacity());
            }
        });
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        blockingQueue.setCapacity(100);
        System.out.println(Thread.currentThread().getName() + "修改容量完成，剩余容量" + blockingQueue.remainingCapacity());
    }
}
